--------------------------------------------------
-- Nueva tabla para limites de credito por cuit --

CREATE SEQUENCE seq_vallimcui
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;
ALTER TABLE seq_ciu
  OWNER TO abacouser;


CREATE TABLE vallimcui
(
  id integer NOT NULL DEFAULT nextval('seq_vallimcui'::regclass), 
  cuit character varying(15) NOT NULL, 
  nombre character varying(45) NOT NULL, 
  codpadlimgru character varying(8), 
  limite numeric(16,2), 
  obse character varying(100), 
  idambdb integer, 
  fechainsert timestamp without time zone, 
  fechaupdate timestamp without time zone, 
  CONSTRAINT vallimcui_pkey PRIMARY KEY (id),
  CONSTRAINT gestion_ai_padlimgruvallimcui FOREIGN KEY (codpadlimgru)
      REFERENCES padlimgru (cod) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE
)
WITH (
  OIDS=TRUE
);
ALTER TABLE vallimcui
  OWNER TO abacouser;
COMMENT ON COLUMN vallimcui.id IS 'Identificador del registro';
COMMENT ON COLUMN vallimcui.cuit IS 'Cuit del librador';
COMMENT ON COLUMN vallimcui.nombre IS 'Nombre del Librador';
COMMENT ON COLUMN vallimcui.codpadlimgru IS 'Codigo del grupo de limite de credito para ese cuit';
COMMENT ON COLUMN vallimcui.limite IS 'Limite de credito para ese cuit';
COMMENT ON COLUMN vallimcui.obse IS 'Observciones y notas';
COMMENT ON COLUMN vallimcui.idambdb IS 'Identificador de la instancia';
COMMENT ON COLUMN vallimcui.fechainsert IS 'Fecha y hora de alta del registro';
COMMENT ON COLUMN vallimcui.fechaupdate IS 'Fecha y hora ultima actualizacion del registro';


-- Index: vallimcui_cuit


CREATE UNIQUE INDEX vallimcui_cuit
  ON vallimcui
  USING btree
  (cuit COLLATE pg_catalog."default");


-- Trigger: control_audit_vallimcui on vallimcui

-- DROP TRIGGER control_audit_vallimcui ON vallimcui;

CREATE TRIGGER control_audit_vallimcui
  BEFORE INSERT OR UPDATE OR DELETE
  ON vallimcui
  FOR EACH ROW
  EXECUTE PROCEDURE tg_control_audit_instancia();

-- ==============================================================
SELECT aaVersion('431.00','430.04');
-- ==============================================================


 